<Window x:Name="window" x:Class="Enterprise_Store.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:src="clr-namespace:Enterprise_Store" 
    Title="List of Products"
        Height="700" Width="1209"
    >    
    
    <Window.Resources>
        <Style TargetType="{x:Type ListBoxItem}">
            <Style.Triggers>
                <Trigger Property="Selector.IsSelected" Value="True">
                    <Setter Property="Background" Value="Moccasin" />
                </Trigger>
            </Style.Triggers>
        </Style>
        <DataTemplate x:Key="groupingHeaderTemplate">
            <TextBlock Text="{Binding Path=Name}"
                       Foreground="Navy" FontWeight="Bold" FontSize="12"/>
        </DataTemplate>

        <Style x:Key="checkBoxStyle" TargetType="{x:Type CheckBox}">
            <Setter Property="Foreground" Value="#333333" />
            <Setter Property="FontWeight" Value="Bold"/>
        </Style>

        
        <CollectionViewSource 
              Source="{Binding Source={x:Static Application.Current}, Path=InstalledApps}"   
              x:Key="appList" />

        <CollectionViewSource 
              Source="{Binding Source={x:Static Application.Current}, Path=CurrentApp}"   
              x:Key="currentApp" />

        <CollectionViewSource 
              Source="{Binding Source={x:Static Application.Current}, Path=W8CSConf}"   
              x:Key="w8csStruct" />
        
        <CollectionViewSource
            Source="{Binding Source={x:Static Application.Current}, Path=InstalledSelectedItem}" x:Key="installedSelectedItem" />
        
    </Window.Resources>

    <Grid Height="{Binding ActualHeight, ElementName=window, Mode=OneWay}">
      <Grid.RowDefinitions>
        <RowDefinition Height="50"/>
        <RowDefinition Height="550"/>
        <RowDefinition Height="50"/>
      </Grid.RowDefinitions>

      <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition Width="50"/>
        <ColumnDefinition/>
        <ColumnDefinition Width="50"/>
        <ColumnDefinition/>
      </Grid.ColumnDefinitions>

        <TextBlock Grid.Row="0" Grid.Column="0"
                   Style="{StaticResource titleStyle}" Margin="8,20,8,8">List of installed applications:</TextBlock>
        <TextBlock Grid.Row="0" Grid.Column="2"
                   Style="{StaticResource titleStyle}" Margin="8,20,8,8">Edit application:</TextBlock>
        <TextBlock Grid.Row="0" Grid.Column="4"
                   Style="{StaticResource titleStyle}" Margin="8,20,8,8">Generated XML:</TextBlock>



        <ListBox Name="Master" Grid.Row="1" Grid.Column="0" Margin="8"
            ItemsSource="{Binding Source={StaticResource appList}}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Height="540">
            <ListBox.GroupStyle>
                <GroupStyle 
                  HeaderTemplate="{StaticResource groupingHeaderTemplate}"/>
            </ListBox.GroupStyle>
        </ListBox>

        <Button Grid.Column="1" Grid.Row="1" HorizontalAlignment="Center" Content="&#xE0AC;" FontFamily="Segoe UI Symbol" VerticalAlignment="Center" FontSize="20"
                Name="editInstalled" Background="White" BorderBrush="White" Click="EditInstalledApp"/>
        
        <ContentControl Name="Detail" Grid.Row="1" Grid.Column="2" 
                Content="{Binding Source={StaticResource currentApp}}" 
                ContentTemplate="{StaticResource detailsProductListingTemplate}" 
                Margin="9,0,0,0"/>
        
        <Grid Grid.Column="3" Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Button Visibility="Hidden" Grid.Row="0" HorizontalAlignment="Center" Content="&#xE0BA;" 
                    FontFamily="Segoe UI Symbol" VerticalAlignment="Bottom" FontSize="20" 
                    Name="edit" Background="White" BorderBrush="White" Click="EditFromW8CSConf"/>
            <Button Grid.RowSpan="2" HorizontalAlignment="Center" Content="&#xE0AC;" 
                    FontFamily="Segoe UI Symbol" VerticalAlignment="Center" FontSize="20" 
                    Name="save" Background="White" BorderBrush="White" Click="AddToW8CSConf"/>
        </Grid>

        <TextBlock Name="xml" Grid.Row="1" Grid.Column="4" Text="{Binding Source={StaticResource currentApp}, Path=Xml}" Margin="8" TextWrapping="Wrap" />

        <Button Name="copyToClipboardButton" Grid.Row="2" Grid.Column="4" Content="Copy to clipboard" HorizontalAlignment="Center" Margin="8" 
            Click="copyToClipboard" />
        
    </Grid>
</Window>